import { TextList } from "../Config";
import ItemView from "./ItemView";
import GridListView from "../engine/GridListView";
import YFDrawCallView from "./YFDrawCallView";

const { ccclass, property } = cc._decorator;

@ccclass
export default class GridListViewTest extends cc.Component {

    @property({ type: YFDrawCallView })
    drawView: YFDrawCallView

    @property(GridListView)
    gridListView: GridListView = null;


    lastItemView:ItemView = null;

    row = 0
    start() {
        this.gridListView.totalCount = TextList.length;
    }

    updateItem(listView, pos: number, item: cc.Node) {
        let text = TextList[pos]
        let itemView: ItemView = item.getComponent(ItemView);
        itemView.content = text;
        itemView.refresh()
        itemView.clickCall = ()=>{
            if(this.lastItemView){
                this.drawView.opacity(this.lastItemView.node.name+'/select', 0)
            }

            let rootName = itemView.node.name
            this.drawView.opacity(rootName +'/select',255)
            this.lastItemView = itemView;
            this.row = pos;
        }
        if (this.lastItemView){
            if (this.row === pos) {
                this.drawView.opacity(itemView.node.name+'/select', 255)
            } else {
                this.drawView.opacity(itemView.node.name+'/select', 0)
            }
        }

    }

    // update (dt) {}

    onBackClick() {
        this.node.destroy()
    }


   public jieshu(){
       this.drawView.ReloadAll()

   }

    areClassesEqual(classA: any, classB: any): boolean {
    return classA.prototype === classB.prototype;
}
}
